package cn.maxhou.sz2.aop;

import org.aspectj.lang.JoinPoint;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Random;

public class PrinterAspect {
    private static final Logger log = LoggerFactory.getLogger(PrinterAspect.class);

    /**
     * 前置增强-打印进入方法和参数
     */
    public void before(JoinPoint jp) {
        Random random = new Random();
        int falg= random.nextInt(10);

        if (falg >= 5&&falg<=7) {
            throw new RuntimeException("打印机卡纸，无法打印！");
        } else if (falg>7&&falg<=9) {
            throw new RuntimeException("打印机墨盒无墨，无法打印！");

        } else {
            System.out.println("打印机自检正常，可以继续打印。");
        }
    }

    /**
     * 后置增强-打印返回结果
     */
    public void afterReturning(JoinPoint jp) {
        System.out.println("打印成功！");

    }
}
